﻿using Microsoft.IdentityModel.Tokens;
using System;
using System.Text;
using Loong.Authentication;
using Loong.Extensions;

namespace Loong.AspNetCore.Authentication
{
    public static class JwtTokenExtensions
    {
        public static SecurityKey GetSecurityKey(this JwtTokenOptions jwtTokenOptions)
        {
            if (jwtTokenOptions.SigningKey.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(jwtTokenOptions.SigningKey));
            }

            return new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtTokenOptions.SigningKey));
        }
    }
}
